<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/7 0007
  Time: 下午 4:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">权限按钮</label>
        <div class="layui-input-block">
            <c:forEach items="${oneList}" var="one">
                <input type="checkbox" lay-filter="chec" name="ids" title="${one.name}" value="${one.id}"
                    <c:if test="${fn:contains(twoList,one.id)}" >checked="checked"</c:if> >
            </c:forEach>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        var $=layui.jquery;
        //监听提交
        form.on('submit(formDemo)', function(data){
            var ids='';//选中的权限按钮
            var allIds='';//所有的权限按钮
            $('input:checkbox[name=ids]:checked').each(function(i){
                //console.log($(this).val());
                ids+=$(this).val()+",";
            });
            $('input:checkbox[name=ids]').each(function(i){
                //console.log($(this).val());
                allIds+=$(this).val()+",";
            });
            //layer.msg(JSON.stringify(data.field));
//            console.log("选中状态的checkBox"+ids);
//            console.log(allIds);
            $.ajax({
                url:'/adminSystem/saveRoleOrUserPermission',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    type:'${type}',
                    id:'${id}',
                    ids:ids,
                    permissionId:'${permissionId}'
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(data){
                    console.log(data);
                    if (data.code=='000000'){
                        layer.msg(data.msg,{time:1000,icon: 6});
                    }else {
                        layer.msg(data.msg,{time:1000,icon: 5});
                    }
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            })






            return false;
        });



    });
</script>

</body>
</html>
